package cn.wolfcode.shop.common;

import lombok.*;

import java.io.Serializable;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> implements Serializable{

    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERORR_CODE = 500000;
    public static final String SUCCESS_MSG = "操作成功";
    public static final String ERORR_MSG = "系统繁忙，请稍后再试";

    private Integer code;
    private String msg;
    private T data;

    public static <T> Result success(T data) {

        return new Result(SUCCESS_CODE,SUCCESS_MSG,data);
    }

    public static Result error(CodeMsg codeMsg){

        return new Result(codeMsg.getCode(),codeMsg.getMsg(),null);
    }

    public static  Result defalutError() {

        return new Result(ERORR_CODE,ERORR_MSG,null);
    }

    public Boolean hasError(){
        return !this.code.equals(SUCCESS_CODE);
    }

}
